package com.xiaogang.ggfw.config.filter;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * @ProjectName : caldav
 * @作者 : 侯小刚
 * @描述 :
 * @创建日期 : 2023/4/10 13:53
 */
@Configuration
public class CorsFileter {

    /**
     * 跨域过滤器
     *
     * @return
     */
    @Bean
    public CorsFilter corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.addAllowedOrigin("*");//访问源地址
        corsConfiguration.addAllowedHeader("*");//访问源请求头
        corsConfiguration.addAllowedMethod("*");//访问源请求方法
        source.registerCorsConfiguration("/**", corsConfiguration); // 接口过滤
        return new CorsFilter(source);
    }

}
